package net.my.msn.service.impl;

import java.util.List;
import net.my.msn.dao.MessageDAO;
import net.my.msn.dao.UserDAO;
import net.my.msn.domain.Message;
import net.my.msn.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class MessageServiceImpl implements MessageService {

	private MessageDAO messageDAO;
	private UserDAO userDAO;

	@Autowired
	public void setUserDao(UserDAO userDAO) {
		this.userDAO = userDAO;
	}

	@Autowired
	public void setMessageDao(MessageDAO messageDAO) {
		this.messageDAO = messageDAO;
	}

	@Transactional
	public void addMessage(String Content, Long id, Long default_id) {
		Message message = new Message();
		message.setSenderId(default_id);
		message.setReceiver(userDAO.read(id));
		message.setMessageContent(Content);
		messageDAO.create(message);

	}

	@Transactional
	public void deleteMessage(Long m_id) {
		Message message = messageDAO.read(m_id);
		messageDAO.delete(message);
	}

	

}
